package com.yukh.test.javabase.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class MySqlT {
	public static void main(String args[]) throws SQLException {
		String DBdriver = "com.mysql.jdbc.Driver";
		String connectURL = "jdbc:mysql://127.0.0.1:3309/spmy";
		String username = "root";
		String password = "111111";
		try {
			Class.forName(DBdriver);
		} catch (ClassNotFoundException e) {
			System.out.println("Error creating class: " + e.getMessage());
		}

		try {
			// connect to DB
			Connection db = DriverManager.getConnection(connectURL, username,
					password);
			Statement stmt = db.createStatement();
			// db = DriverManager.getConnection(connectURL,username,password);
			// 去掉这行

			stmt.close();
			db.close();
		} catch (SQLException ex) {
			System.err.println("==> SQLException: ");
			while (ex != null) {
				System.out.println("Message: " + ex.getMessage());
				System.out.println("SQLState: " + ex.getSQLState());
				System.out.println("ErrorCode: " + ex.getErrorCode());
				ex = ex.getNextException();
				System.out.println("");
			}
		}
	}
}
